package kr.hkit.powerjava.coffee.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import kr.hkit.powerjava.chapter26.common.DbUtil;
import kr.hkit.powerjava.coffee.dto.Product;

public class ProductDao {
	private Connection connection;
	private PreparedStatement pstmt;
	
	public ProductDao(Connection connection) {
		this.connection = connection;
	}
	

	public void insertItem(Product item) throws SQLException {
		String sql = "insert into product values(?, ?, ?, ?, ?, ?, ?, ?)";
		
		pstmt = connection.prepareStatement(sql);
		pstmt.setString(1, item.getCode());
		pstmt.setInt(2, item.getPrice());
		pstmt.setInt(3, item.getAmount());
		pstmt.setInt(4, item.getSupply());
		pstmt.setInt(5, item.getSurtax());
		pstmt.setInt(6, item.getSellingPrice());
		pstmt.setInt(7, item.getMargin());
		pstmt.setInt(8, item.getMarginSum());
		pstmt.executeUpdate();
		DbUtil.close(pstmt);
	}
	
}
